package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"jd.com-user-system/appconfig"
)

var (
	Db  *gorm.DB
	err error
)

func Init() {

	appConfig := appconfig.AppConfig.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True", appConfig.User, appConfig.Password, appConfig.Host, appConfig.Port, appConfig.Database)
	Db, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		fmt.Println("数据库连接失败")
	} else {
		fmt.Println("MySQL连接成功")
	}
	Db.AutoMigrate(&User{})

}
